package com.ktwlsoft.fundmanage.controller;

import com.ktwlsoft.fundmanage.domain.business.FundInService;
import com.ktwlsoft.fundmanage.domain.business.SystemService;
import com.ktwlsoft.fundmanage.domain.entity.BankInfo;
import com.ktwlsoft.fundmanage.domain.entity.GroupDuty;
import com.ktwlsoft.fundmanage.domain.entity.PayInType;
import com.ktwlsoft.fundmanage.domain.entity.pictureconfig.SignCredential;
import com.ktwlsoft.fundmanage.payload.BaseResult;
import com.ktwlsoft.fundmanage.payload.PropertyRightTransferRequest;
import com.ktwlsoft.fundmanage.payload.ResultType;
import com.ktwlsoft.fundmanage.service.BankInfoService;
import com.ktwlsoft.fundmanage.service.PayInTypeService;
import com.ktwlsoft.fundmanage.service.UserTaskConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "系统配置相关查询，作者：朱和")
@RestController
@RequestMapping("/system")
public class SystemController {

    /**用户任务配置*/
    private final UserTaskConfigService userTaskConfigService;

    /**银行账号配置*/
    private final BankInfoService bankInfoService;

    /**资金流程操作*/
    private final FundInService fundInService;

    /**出账入账类型配置*/
    private final PayInTypeService payInTypeService;

    private final SystemService systemService;

    public SystemController(UserTaskConfigService userTaskConfigService, BankInfoService bankInfoService, FundInService fundInService, PayInTypeService payInTypeService, SystemService systemService){
        this.userTaskConfigService = userTaskConfigService;
        this.bankInfoService = bankInfoService;
        this.fundInService = fundInService;
        this.payInTypeService = payInTypeService;
        this.systemService = systemService;
    }

    /**
     * 用户任务配置-获取所有用户任务 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "用户任务配置-获取所有用户任务", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("getUserTaskAll")
    public ResponseEntity<?> getUserTaskAll(){
        return ResponseEntity.ok(userTaskConfigService.findAll());
    }

    /**
     * 用户任务配置-新增或修改(目前只能用于修改) on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "用户任务配置-新增或修改(目前只能用于修改)", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("userTaskConfigBindSave")
    public ResponseEntity<?> userTaskConfigBindSave(@RequestBody GroupDuty groupDuty){
        return ResponseEntity.ok(userTaskConfigService.save(groupDuty));
    }

    /**
     * 用户任务配置-删除 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "用户任务配置-删除", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("delete")
    public ResponseEntity<?> delete(@RequestBody GroupDuty groupDuty){
//		return ResponseEntity.ok(userTaskConfigService.delete(groupDuty));
        return ResponseEntity.ok(BaseResult.body(null, ResultType.BUSINESS_ERROR).withMessage("删除暂不可用"));
    }

    /**
     * 用户任务配置-修改是否启用 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "用户任务配置-修改是否启用", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("updateActive")
    public ResponseEntity<?> updateActive(@ApiParam(name = "id", value = "用户任务配置id") @RequestParam(defaultValue = "", required = false) Long id){
        return ResponseEntity.ok(userTaskConfigService.updateActive(id));
    }

    /**
     * 银行账号配置-银行分页 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "银行账号配置-银行分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("bankConfigPage")
    public ResponseEntity<?> bankConfigPage(@RequestParam(defaultValue = "1") int pn,
                                            @RequestParam(defaultValue = "30") int pageSize,
                                            @ApiParam(name = "keyWords", value = "关键词") @RequestParam(defaultValue = "", required = false) String keyWords,
                                            @ApiParam(name = "businessType", value = "业务类型") @RequestParam(defaultValue = "", required = false) BankInfo.BusinessType businessType,
                                            @ApiParam(name = "bankType", value = "银行类型") @RequestParam(defaultValue = "", required = false) BankInfo.BankType bankType){
        return ResponseEntity.ok(bankInfoService.findPage(pn,pageSize,keyWords,businessType,bankType,"bank"));
    }

    /**
     * 银行账号配置-账号分页 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "银行账号配置-账号分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("bankNumberPage")
    public ResponseEntity<?> bankNumberPage(@RequestParam(defaultValue = "1") int pn,
                                            @RequestParam(defaultValue = "30") int pageSize,
                                            @ApiParam(name = "keyWords", value = "关键词") @RequestParam(defaultValue = "", required = false) String keyWords,
                                            @ApiParam(name = "businessType", value = "业务类型") @RequestParam(defaultValue = "", required = false) BankInfo.BusinessType businessType,
                                            @ApiParam(name = "bankType", value = "银行类型") @RequestParam(defaultValue = "", required = false) BankInfo.BankType bankType){
        return ResponseEntity.ok(bankInfoService.findPage(pn,pageSize,keyWords,businessType,bankType,"number"));
    }

    /**
     * 银行账号配置-新增或修改 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "银行账号配置-新增或修改", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("bankConfigSave")
    public ResponseEntity<?> bankConfigSave(@RequestBody BankInfo bankInfo){
        return ResponseEntity.ok(bankInfoService.save(bankInfo));
    }

    /**
     * 银行账号配置-详情 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "银行账号配置-详情", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("bankConfigDetails")
    public ResponseEntity<?> bankConfigDetails(@ApiParam(name = "id", value = "主键") @RequestParam(defaultValue = "") Long id){
        return ResponseEntity.ok(bankInfoService.getDetails(id));
    }

    /**
     * 银行账号配置-启用禁用 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "银行账号配置-启用禁用", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("bankUpdateActive")
    public ResponseEntity<?> bankUpdateActive(@ApiParam(name = "id", value = "主键") @RequestParam(defaultValue = "") Long id){
        return ResponseEntity.ok(bankInfoService.updateActive(id));
    }

    /**
     * 银行账号配置-删除 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "银行账号配置-删除", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("bankConfigDelete")
    public ResponseEntity<?> bankConfigDelete(@ApiParam(name = "id", value = "主键") @RequestParam(defaultValue = "") Long id){
        return ResponseEntity.ok(bankInfoService.delete(id));
    }

    /**
     * 划款管理-产权过户 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "划款管理-产权过户", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("propertyRightTransfer")
    public ResponseEntity<?> propertyRightTransfer(@RequestBody PropertyRightTransferRequest propertyRightTransferRequest){
        return ResponseEntity.ok(fundInService.propertyRightTransfer(propertyRightTransferRequest.getTsCode(),
                propertyRightTransferRequest.getOwnershipNo(),propertyRightTransferRequest.getSignCredentials()));
    }

    /**
     * 划款管理-选择需划付的资金 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "划款管理-选择需划付的资金", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("needPayCapital")
    public ResponseEntity<?> needPayCapital(@RequestParam(defaultValue = "1") int pn,
                                            @RequestParam(defaultValue = "30") int pageSize,
                                            @ApiParam(name = "tsCode", value = "交易编号") @RequestParam(defaultValue = "") Long tsCode,
                                            @ApiParam(name = "dnCode", value = "划款单号") @RequestParam(defaultValue = "") Long dnCode,
                                            @ApiParam(name = "fundInCode", value = "入账id") @RequestParam(defaultValue = "") Long fundInCode){
        return ResponseEntity.ok(fundInService.needPayCapital(pn,pageSize,tsCode,dnCode,fundInCode));
    }

    /**
     * 退款管理-开具退款单-划款信息 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "退款管理-开具退款单-划款信息", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("openingRefundSlip")
    public ResponseEntity<?> openingRefundSlip(@RequestParam(defaultValue = "1") int pn,
                                            @RequestParam(defaultValue = "30") int pageSize,
                                            @ApiParam(name = "tsCode", value = "交易编号") @RequestParam(defaultValue = "") Long tsCode){
        return ResponseEntity.ok(fundInService.openingRefundSlip(pn,pageSize,tsCode));
    }

    /**
     * 退款管理-开具退款单-业务信息 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "退款管理-开具退款单-业务信息", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("businessInformation")
    public ResponseEntity<?> businessInformation(@ApiParam(name = "tsCode", value = "交易编号") @RequestParam(defaultValue = "") Long tsCode){
        return ResponseEntity.ok(fundInService.businessInformation(tsCode));
    }

    /**
     * 出账入账类型配置-分页 on 2019/8/15 18:35
     *
     * @return payinTypePage<?>
     */
    @ApiOperation(value = "出账入账类型配置-分页,前端传递分页参数类似于page=0&size=2&sort=createdAt,desc", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("payinTypePage")
    public ResponseEntity<?> payinTypePage(@RequestParam(defaultValue = "1") int pn,
                                           @RequestParam(defaultValue = "30") int pageSize,
                                           @ApiParam(name = "payType", value = "支付类型") @RequestParam(defaultValue = "") String payType,
                                           @ApiParam(name = "keyWords", value = "属性名称") @RequestParam(defaultValue = "") String keyWords){
        return ResponseEntity.ok(payInTypeService.payinTypePage(payType,keyWords,pn,pageSize));
    }

    /**
     * 出账入账类型配置-新增或修改 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "出账入账类型配置-新增或修改", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("payinTypeSave")
    public ResponseEntity<?> payinTypeSave(@RequestBody PayInType payInType){
        return ResponseEntity.ok(payInTypeService.payinTypeSave(payInType));
    }

    /**
     * 出账入账类型配置-删除 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "出账入账类型配置-删除", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("payinTypeDelete")
    public ResponseEntity<?> payinTypeDelete(@ApiParam(name = "id", value = "主键") @RequestParam(defaultValue = "") Long id){
        return ResponseEntity.ok(payInTypeService.payinTypeDelete(id));
    }

    /**
     * 出账入账类型配置-启用禁用 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "出账入账类型配置-启用禁用", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("payinTypeUpdateActive")
    public ResponseEntity<?> payinTypeUpdateActive(@ApiParam(name = "id", value = "主键") @RequestParam(defaultValue = "") Long id){
        return ResponseEntity.ok(payInTypeService.payinTypeUpdateActive(id));
    }

    /**
     * 跳过配置-分页 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "跳过配置-分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("findSkipConfigPage")
    public ResponseEntity<?> findSkipConfigPage(@RequestParam(defaultValue = "1") int pn,
                                                @RequestParam(defaultValue = "30") int pageSize,
                                                @ApiParam(name = "systemType", value = "系统类型") @RequestParam(defaultValue = "") String systemType){
        return ResponseEntity.ok(systemService.findSkipConfigPage(pn,pageSize,systemType));
    }

    /**
     * 跳过配置-详情 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "跳过配置-详情", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("getSkipConfigDetails")
    public ResponseEntity<?> getSkipConfigDetails(@ApiParam(name = "systemType", value = "系统类型") @RequestParam(defaultValue = "") String systemType){
        return ResponseEntity.ok(systemService.getSkipConfigDetails(systemType));
    }

    /**
     * 跳过配置-是否跳过 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "跳过配置-是否跳过", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("skipConfigUpdateSkip")
    public ResponseEntity<?> skipConfigUpdateSkip(@ApiParam(name = "systemType", value = "系统类型") @RequestParam(defaultValue = "") String systemType){
        return ResponseEntity.ok(systemService.skipConfigUpdateSkip(systemType));
    }

    /**
     * 跳过配置-是否跳过 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "跳过配置-是否跳过", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("skipConfigUpdateSkipOptional")
    public ResponseEntity<?> skipConfigUpdateSkipOptional(@ApiParam(name = "systemType", value = "系统类型") @RequestParam(defaultValue = "") String systemType,
                                                  @ApiParam(name = "skip", value = "现在是否跳过") @RequestParam(defaultValue = "") Boolean skip){
        return ResponseEntity.ok(systemService.skipConfigUpdateSkip(systemType,skip));
    }
}
